﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="$safeitemrootname$.aspx.cs" Inherits="$rootnamespace$.$safeitemrootname$" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <asp:PlaceHolder ID="PlaceHolder1" runat="server"> 
        <%: Scripts.Render("~/bundles/JQuery") %>   
        <%: Scripts.Render("~/bundles/JQueryUI") %>   
        <%: Styles.Render("~/bundles/Formly/css") %>
        <%: Scripts.Render("~/bundles/Formly") %>
    </asp:PlaceHolder>
          
    <link type="text/css" rel="stylesheet" href="/assets/css/bootstrap/bootstrap.min.css" />
    <link type="text/css" rel="stylesheet" href="/assets/css/bootstrap/bootstrap-themes.css" />
    <link type="text/css" rel="stylesheet" href="/assets/css/style.css" />

    <script type="text/javascript" lang="javascript" src="/Scripts/Formly/FormlyHelper.js"></script>
    <script type="text/javascript" lang="javascript" src="/Scripts/GrayParrot.Core.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.AngularJS.Directives.DateTimePicker.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.AngularJS.Directives.FileUpload.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.AngularJS.js"></script> 

    <script type="text/javascript" src="/assets/plugins/bootstrap/bootstrap.min.js"></script>

    <title>Grid CRUD Page</title>

      <style>
          body {
            margin: 20px;
            background-color:#ffffff;
          }

          .formly-field {
            margin-bottom: 16px;
          }
      </style>
</head>

<body ng-app="formlyExample" ng-controller="MainCtrl as vm" id="divAvvManuale">

<%--    <h1>GRID CRUD Page<br /><hr /></h1>--%>
    <div ng-if="vm.loadingData.$$state.status === 0" style="margin:20px 0;font-size:2em">
        <strong>Loading...</strong>
    </div>
    <div ng-if="vm.loadingData.$$status.state !== 0">
        <form ng-submit="vm.onSubmit()" novalidate>
            <formly-form model="vm.model" fields="vm.fields" form="vm.form">
            <button type="sumbit" class="btn btn-primary submit-button" ng-disabled="vm.form.$invalid">Submit</button> <!-- ng-click="ok()" -->
            </formly-form>
        </form>
    </div>

</body>

   <script>
       /*
          FormlyManager parameters:
          container:         id of the formly containing div
          callbackSuccess:   callback function called on success
          callbackError:     callback function called in error
          shortcutCallback:  callback function called instead of the canonical send function ( if use this, not indicate the send function )
          onloadCallback:    callback function called on load
          beforeSumbit:      callback function called before the submit
       */
       var idToEdit = GetQueryStringParams("id");

       var settings = new FormlySettings();
       settings.container = '#divAvvManuale';
       settings.callbackSuccess = SuccessCallback;

       if (idToEdit == undefined) {
           settings.setLoad(settings.createGetConfig('/api/CONTROLLER_NAME/LOAD_FIELDS_METHOD_NAME'));
           settings.setSend(settings.createPostConfig('/api/CONTROLLER_NAME/ADD_FIELDS_METHOD_NAME'));
        } else {
           settings.setLoad(settings.createGetConfig('/api/CONTROLLER_NAME/LOAD_FIELDS_METHOD_NAME_WITH_ID', { id: idToEdit }));
           settings.setSend(settings.createPostConfig('/api/CONTROLLER_NAME/EDIT_FIELDS_METHOD_NAME'));
       }

       FormlyManager(settings);

       /* */
       function SuccessCallback(response) {
           window.parent.CloseDialog(response);
       }
   </script>

</html>
